package com.dfy.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dfy.entity.Order;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OrderMapper extends BaseMapper<Order> {
    @Delete("DELETE FROM orders WHERE spot_id = #{spotId}")
    int deleteBySpotId(@Param("spotId") Long spotId);

    @Select("SELECT o.*, s.name as spot_name FROM orders o " +
           "LEFT JOIN spots s ON o.spot_id = s.id " +
           "WHERE o.user_id = #{userId} " +
           "AND (#{status} = 'ALL' OR o.status = #{status}) " +
           "ORDER BY o.created_at DESC")
    List<Order> selectOrdersByUserId(@Param("userId") Long userId, @Param("status") String status);
} 